// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Gargoyle Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 53 : TYPE_GARGOYLE

// Function declarations
reserve function Gargoyle_DebugDraw
reserve function Gargoyle_DebugSpawn

// Static Values

// Tables

function Gargoyle_DebugDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
end function


function Gargoyle_DebugSpawn
	CreateTempObject(TypeName[Gargoyle], 0, object.xpos, object.ypos)
	object[tempObjectPos].direction = object.direction
	object[tempObjectPos].value1 = 60
	object[tempObjectPos].value0 = 60
end function


event ObjectMain
	temp0 = object.ixpos
	temp0 -= screen.cameraX
	Abs(temp0)
	if temp0 < screen.xcenter
		temp0 = object.iypos
		temp0 -= screen.cameraY
		Abs(temp0)
		if temp0 < screen.ycenter		
			
				object.value2 = 1
				object.value0--
				if object.value0 <= 0
					PlaySfx(SfxName[Thud], 0)
					CreateTempObject(TypeName[Gargoyle Shot], 0, object.xpos, object.ypos)
					object[tempObjectPos].drawOrder = 1
					if object.direction == FLIP_NONE
						object[tempObjectPos].xvel = -0x20000
					else
						object[tempObjectPos].xvel = 0x20000
					end if
					//object[tempObjectPos].ypos += 0x80000
					object[tempObjectPos].direction = object.direction
					object.value0 = object.value1
				end if
			
		end if
	end if
end event


event ObjectDraw	
	if object.direction == 0
		DrawSpriteXY(0, object.xpos, object.ypos)
		DrawSpriteXY(1, object.xpos, object.ypos)
	else
		DrawSpriteXY(3, object.xpos, object.ypos)	
		DrawSpriteXY(4, object.xpos, object.ypos)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("MBZ/Objects.gif")
	SpriteFrame(0, -16, 16, 32, 1, 438) //0 Main Circle Left
	SpriteFrame(-5, -6, 12, 12, 1, 423) //1 Cannon left
	SpriteFrame(-3, 5, 14, 14, 29, 408) //2 Cannon downleft	
	
	SpriteFrame(-16, -16, 16, 32, 18, 438) //3 Main Circle Right
	SpriteFrame(-7, -6, 12, 12, 29, 393) //4 Cannon right
	SpriteFrame(-11, 5, 14, 14, 1, 408) //5 Cannon downright
	
	foreach (TypeName[Gargoyle], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = 4
		object[arrayPos0].value1 *= 30
		object[arrayPos0].value0 = object[arrayPos0].value1
		object[arrayPos0].direction = object[arrayPos0].propertyValue
	next
	SetTableValue(TypeName[Gargoyle], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(Gargoyle_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(Gargoyle_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
